package org.dzq.designmode.proxy.dynamicproxy;

import org.dzq.designmode.proxy.Animal;
import org.dzq.designmode.proxy.Cat;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName: Proxy
 * @Package: org.dzq.designmode.proxy.dynamicproxy
 * @author: 越
 * @date: 2023/6/17 12:29
 * @Description: JDK动态代理，需要被代理类实现接口
 */
public class InvocationHandlerImpl implements InvocationHandler {

    private Object object;

    public InvocationHandlerImpl(Object object){
        this.object = object;
    }

    public void sleep(){
        System.out.println("吃饱了就睡");
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(object,args);
        sleep();
        return result;
    }
}
